package com.example.shop_2208.fragment

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.launcher.ARouter
import com.example.shop_2208.R
import com.example.shop_2208.adapter.PayAdapter
import com.example.shop_2208.databinding.FragmentPayedBinding
import com.example.shop_2208.db.MyDbUtils
import com.example.shop_2208.mvvm.BaseViewFragment


class PayedFragment : BaseViewFragment<FragmentPayedBinding>() {
    lateinit var payAdapter: PayAdapter
    override fun initData() {

    }

    override fun initView() {
        payAdapter = PayAdapter()
        binding.rvPayed.adapter = payAdapter
        binding.rvPayed.layoutManager = LinearLayoutManager(context)

        val data = MyDbUtils.getDb().getOrderDao().queryStatus(2)//已支付的订单
        payAdapter.data.clear()
        payAdapter.data.addAll(data)
        payAdapter.notifyDataSetChanged()
        //点击去评价跳转到评价界面
        payAdapter.addChildClickViewIds(R.id.toComment)
        payAdapter.setOnItemChildClickListener { adapter, view, position ->
            when (view.id){
                R.id.toComment->ARouter.getInstance().build("/app/CommentActivity").navigation()
            }
        }

    }

    override fun getLayout(): Int  = R.layout.fragment_payed

}